import { cloneDeep, } from 'lodash-es';

let userList: UserRecord[] = [
  { userId: 1, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:03', userDescribe: '描述', },
  { userId: 2, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:04', userDescribe: '描述', },
  { userId: 3, userName: '名字', userAge: '年龄', userSex: '1', userImg: '0', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:05', userDescribe: '描述', },
  { userId: 4, userName: '名字', userAge: '年龄', userSex: '1', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:06', userDescribe: '描述', },
  { userId: 5, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:07', userDescribe: '描述', },
  { userId: 6, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:08', userDescribe: '描述', },
  { userId: 7, userName: '名字', userAge: '年龄', userSex: '1', userImg: '0', userInterest: ['1', '1'], userBirthdayTime: '2025-01-20 23:07:09', userDescribe: '描述', },
  { userId: 8, userName: '名字', userAge: '年龄', userSex: '1', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2025-01-20 23:07:10', userDescribe: '描述', },
  { userId: 9, userName: '名字', userAge: '年龄', userSex: '1', userImg: '0', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:11', userDescribe: '描述', },
  { userId: 10, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:12', userDescribe: '描述', },
  { userId: 11, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:13', userDescribe: '描述', },
  { userId: 12, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:14', userDescribe: '描述', },
  { userId: 13, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:15', userDescribe: '描述', },
  { userId: 14, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:16', userDescribe: '描述', },
  { userId: 15, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['1', '1'], userBirthdayTime: '2025-01-20 23:07:17', userDescribe: '描述', },
  { userId: 16, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2025-01-20 23:07:18', userDescribe: '描述', },
  { userId: 17, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:19', userDescribe: '描述', },
  { userId: 18, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:20', userDescribe: '描述', },
  { userId: 19, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:21', userDescribe: '描述', },
  { userId: 20, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:22', userDescribe: '描述', },
  { userId: 21, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:23', userDescribe: '描述', },
  { userId: 22, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2025-01-20 23:07:24', userDescribe: '描述', },
  { userId: 23, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:25', userDescribe: '描述', },
  { userId: 24, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:26', userDescribe: '描述', },
  { userId: 25, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2025-01-20 23:07:27', userDescribe: '描述', },
  { userId: 26, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:28', userDescribe: '描述', },
  { userId: 27, userName: '名字', userAge: '年龄', userSex: '1', userImg: '0', userInterest: ['0', '0'], userBirthdayTime: '2025-01-20 23:07:29', userDescribe: '描述', },
  { userId: 28, userName: '名字', userAge: '年龄', userSex: '1', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2025-01-20 23:07:30', userDescribe: '描述', },
  { userId: 29, userName: '名字', userAge: '年龄', userSex: '0', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2025-01-20 23:07:31', userDescribe: '描述', },
  { userId: 30, userName: '名字', userAge: '年龄', userSex: '0', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2025-01-20 23:07:32', userDescribe: '描述', },
];

const mocks: MockRecord[] = [
  {
    method: 'get',
    url: '/api/system/user/list',
    response(option) {
      const copyList = cloneDeep(userList);
      
      let resList = userList;
      
      if (option.query.pageNum) {
        resList = copyList.splice((option.query.pageNum - 1) * option.query.pageSize, option.query.pageSize);
      }
      
      const resData: responseType = {
        code: 200,
        msg: '查询成功',
        total: userList.length,
        ...(option.query.pageNum ? { rows: resList } : { data: resList })
      }
      
      return resData;
    }
  },
  {
    method: 'get',
    url: '/api/system/user/:userId',
    response(option) {
      const resUser = userList.find(item => item.userId == option.query.userId);

      const resData: responseType = {
        code: resUser ? 200 : 500,
        msg: resUser ? '查询成功' : '查询失败',
        data: resUser,
      }
      
      return resData;
    }
  },
  {
    method: 'post',
    url: '/api/system/user',
    response(option) {
      const newUser = option.body;
      
      newUser.userId = userList.length + 1;
      userList.unshift(newUser);
      
      const resData: responseType = {
        code: 200,
        msg: '新增成功',
      }
      
      return resData;
    }
  },
  {
    method: 'put',
    url: '/api/system/user',
    response(option) {
      const newUser = option.body;
      
      const index = userList.findIndex(item => item.userId == newUser.userId);
      
      userList.splice(index, 1, newUser);
      
      const resData: responseType = {
        code: 200,
        msg: '修改成功',
      }
      
      return resData;
    }
  },
  {
    method: 'delete',
    url: '/api/system/user/:userIds',
    response(option) {
      const userIds = option.query.userIds.split(',');
      
      const filterList = userList.filter(item => !userIds.includes(String(item.userId)));
      
      userList = filterList;
      
      const resData: responseType = {
        code: 200,
        msg: '删除成功',
      }
      return resData;
    }
  }
];

export default mocks;